import { Observable } from 'rxjs';
import { BaseTreeNode, FilterConfig } from '../core/api';

export type TreeCallback = (source: TreeNode) => boolean | Promise<boolean> | Observable<boolean>;

export enum EventName {
  CLICK = 'click',
  DBLCLICK = 'dblclick',
  CHECK = 'check',
}

export interface TreeDragDrop {
  renderData: TreeNode[];
  previousIndex: number;
  currentIndex: number;
}

export interface TreeFilterConfig extends FilterConfig {
  customItemFilter?: <T>(data: T | null, filter: TreeFilterConfig) => boolean;
}

export interface TreeNode extends BaseTreeNode {
  [key: string]: any;
  label: string;
  expandedToggleIcon?: { true?: string; false?: string } | string;
  contentToggleIcon?: { true?: string; false?: string } | string;
  icon?: string; // 未使用
  hidden?: boolean;
  isLoading?: boolean;
  indeterminate?: boolean; // 半选状态
  // selected?: boolean; // NEED_DO: 配置节点是否被选中
  showCheckbox?: boolean; // 是否显示checkbox
  level?: number; // 层级
  parent?: TreeNode;
  children?: TreeNode[];
  _lv_isStart?: boolean[];
  _lv_isEnd?: boolean[];
  _lv_level?: number;
  _lv_id?: string; // 作为不传入key时的节点的唯一标识
}

export interface FlattenNode extends BaseTreeNode {
  [key: string]: any;
  parent?: FlattenNode;
  children: FlattenNode[];
  pos: string;
  data: TreeNode;
  _lv_isStart: boolean[];
  _lv_isEnd: boolean[];
  _lv_level?: number;
  _lv_id?: string; // 作为不传入key时的节点的唯一标识
}

export type TreeNodeKey = string | number;

export interface TreeNodeExtra {
  [key: string]: any;
  getNodeLevel?: boolean;
}
